package com.thirdgroup.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @BelongsProject: login_test
 * @BelongsPackage: com.zys.filter
 * @Author: ZYS
 * @CreateTime: 2024-04-20  09:51
 * @Description: TODO
 */


@WebFilter(filterName = "characterEncodingFilter",urlPatterns = "/*")
public class CharacterEncodingFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //设置编码解码字符集
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setCharacterEncoding("utf-8");

        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    public void destroy() {

    }
}
